﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace gradeManager
{
    public partial class RegisterForm : Form
    {
        public RegisterForm()
        {
            InitializeComponent();
        }
        private void 注册_Load(object sender, EventArgs e)
        {

            MaximizeBox = false;        //关闭注册窗口的最大化功能
            button1.Enabled = false; //用户未输入注册信息时，默认注册按钮不可点击

            Verification_Code.Text = VerificationCode.Code(); //加载验证码
        }



        //返回
        private void button2_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }
        //注册
        private void button1_Click(object sender, EventArgs e)
        {
            LinkSqLiteDB db = new LinkSqLiteDB();   //创建数据库连接对象
            if (db.DBconn())

            { //连接数据库
                string str = "insert into login_info(stuid,password,stuname) values ('" + textBox1.Text + "','" + textBox3.Text + "','" + textBox2.Text + "');";
                string info = "注册成功！";

                if (db.UpdataDeletAdd(str))
                {
                    DialogResult dr = MessageBox.Show(info, "标题", MessageBoxButtons.OK, MessageBoxIcon.Question);
                    if (dr == DialogResult.OK)
                    {
                        this.Visible = false;//隐藏当前窗口
                    }
                }
            }

            db.DBclose();//关闭数据连接
        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        //当用户输入学号时验证该学号是否可以注册
        private void textBox1_Leave(object sender, EventArgs e)
        {
            LinkSqLiteDB db = new LinkSqLiteDB();   //创建数据库连接对象
            if (db.DBconn())
            {          //创建数据库连接
                string str = "select * from login_info where stuid ='" + textBox1.Text + "'";
                if (db.GetLoginData(str))//执行sql检测该用户是否已经被注册
                {
                    MessageBox.Show("该用户已经存在!");
                }

            }
            db.DBclose();   //关闭数据库连接
        }
        //当第二次输入密码被弹起时验证密码是否一致
        private void textBox4_KeyUp(object sender, KeyEventArgs e)
        {
            if (!textBox3.Text.Equals(textBox4.Text))
            {
                MessageBox.Show("密码不一致！");
            }
        }
    
        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click_1(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void textBox5_Leave(object sender, EventArgs e)
        {

        }

        private void textBox4_Leave(object sender, EventArgs e)
        {

            if (!textBox3.Text.Equals(textBox4.Text))
            {
                MessageBox.Show("密码不一致！");
            }

        }

        private void textBox5_KeyUp(object sender, KeyEventArgs e)
        {
            if (!textBox5.Text.Equals(Verification_Code.Text))
            {
                label8.Text = "";
                MessageBox.Show("验证码不正确，请重新输入！");
                button1.Enabled = false;
            }
            else
            {
                label8.Text = "";
                button1.Enabled = true;
            }

        }
    }
}